# plot_storage2.py
import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv('docs/storage_compare.csv')

plt.rcParams['font.sans-serif'] = ['SimHei', 'Arial Unicode MS']
plt.rcParams['axes.unicode_minus'] = False

fig, ax = plt.subplots(figsize=(10, 6))

x = df['index']
width = 0.4

# 绘制两组柱状图
bars1 = ax.bar(x - width/2, df['full(B)'], width, label='全量存储 (Full Config)', color='skyblue', edgecolor='navy', alpha=0.8)
bars2 = ax.bar(x + width/2, df['diff(B)'], width, label='差异存储 (Minimal Diff)', color='lightcoral', edgecolor='darkred', alpha=0.8)

# 添加数据标签
for bars in [bars1, bars2]:
    for bar in bars:
        height = bar.get_height()
        ax.text(bar.get_x() + bar.get_width()/2, height + 2,
                f'{int(height)} B', ha='center', va='bottom', fontsize=10)

ax.set_title('图 4-1 配置存储方式对比（全量 vs 差异）', fontsize=14, fontweight='bold', pad=20)
ax.set_xlabel('配置版本', fontsize=12)
ax.set_ylabel('存储大小（字节）', fontsize=12)
ax.set_xticks(df['index'])
ax.set_xticklabels([f'V{i}' for i in df['index']])
ax.legend(fontsize=11)
ax.grid(axis='y', alpha=0.3, linestyle='--')

plt.tight_layout()
plt.savefig('docs/storage_compare.png', dpi=300, bbox_inches='tight')
plt.show()